

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/favicon.png">
  <link rel="icon" href="/favicon.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="wendao">
  <meta name="keywords" content="">
  
    <meta name="description" content="不同的项目使用的java版本不同，每次切换时都需要手动去修改java的环境变量，麻烦至极。jenv可以管理java版本，轻松实现管理多个java的问题。一、下载jenv1$ git clone https:&#x2F;&#x2F;github.com&#x2F;gcuisinier&#x2F;jenv.git ~&#x2F;.jenv  二、配入环境变量1$ echo &amp;#x27;export PATH&#x3D;&quot;$HOME&#x2F;.jenv&#x2F;bin">
<meta property="og:type" content="article">
<meta property="og:title" content="linux下java版本管理工具jenv使用介绍">
<meta property="og:url" content="http://example.com/2019/05/02/java-env-ubuntu/index.html">
<meta property="og:site_name" content="WeData">
<meta property="og:description" content="不同的项目使用的java版本不同，每次切换时都需要手动去修改java的环境变量，麻烦至极。jenv可以管理java版本，轻松实现管理多个java的问题。一、下载jenv1$ git clone https:&#x2F;&#x2F;github.com&#x2F;gcuisinier&#x2F;jenv.git ~&#x2F;.jenv  二、配入环境变量1$ echo &amp;#x27;export PATH&#x3D;&quot;$HOME&#x2F;.jenv&#x2F;bin">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2019-05-02T09:46:36.000Z">
<meta property="article:modified_time" content="2023-07-03T23:02:25.101Z">
<meta property="article:author" content="wendao">
<meta property="article:tag" content="教程">
<meta property="article:tag" content="linux">
<meta property="article:tag" content="ubuntu">
<meta name="twitter:card" content="summary_large_image">
  
  
  
  <title>linux下java版本管理工具jenv使用介绍 - WeData</title>

  <link  rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://cdn.staticfile.org/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  <link  rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_kmeydafke9r.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.2","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.2.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>WeData</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/links/">
                <i class="iconfont icon-link-fill"></i>
                友链
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_960_720.jpg') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="linux下java版本管理工具jenv使用介绍"></span>
          
        </div>

        
          
  <div class="mt-3">
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2019-05-02 17:46" pubdate>
          2019年5月2日 下午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          <!-- compatible with older versions-->
          745 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          <!-- compatible with older versions-->
          7 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">linux下java版本管理工具jenv使用介绍</h1>
            
            
              <div class="markdown-body">
                
                <h6 id="不同的项目使用的java版本不同，每次切换时都需要手动去修改java的环境变量，麻烦至极。jenv可以管理java版本，轻松实现管理多个java的问题。"><a href="#不同的项目使用的java版本不同，每次切换时都需要手动去修改java的环境变量，麻烦至极。jenv可以管理java版本，轻松实现管理多个java的问题。" class="headerlink" title="不同的项目使用的java版本不同，每次切换时都需要手动去修改java的环境变量，麻烦至极。jenv可以管理java版本，轻松实现管理多个java的问题。"></a>不同的项目使用的java版本不同，每次切换时都需要手动去修改java的环境变量，麻烦至极。jenv可以管理java版本，轻松实现管理多个java的问题。</h6><h5 id="一、下载jenv"><a href="#一、下载jenv" class="headerlink" title="一、下载jenv"></a>一、下载jenv</h5><figure class="highlight awk"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs awk">$ git clone https:<span class="hljs-regexp">//gi</span>thub.com<span class="hljs-regexp">/gcuisinier/</span>jenv.git ~/.jenv<br></code></pre></td></tr></table></figure>

<h5 id="二、配入环境变量"><a href="#二、配入环境变量" class="headerlink" title="二、配入环境变量"></a>二、配入环境变量</h5><figure class="highlight julia"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs julia">$ echo &#x27;<span class="hljs-keyword">export</span> PATH=<span class="hljs-string">&quot;<span class="hljs-variable">$HOME</span>/.jenv/bin:<span class="hljs-variable">$PATH</span>&quot;</span>&#x27; &gt;&gt; ~/.bash_profile<br></code></pre></td></tr></table></figure>

<h5 id="三、执行-jenv-init-命令，这样每打开一个-bash-终端就可以调用-jenv-命令，并且默认执行一次-jenv-init-命令。"><a href="#三、执行-jenv-init-命令，这样每打开一个-bash-终端就可以调用-jenv-命令，并且默认执行一次-jenv-init-命令。" class="headerlink" title="三、执行 jenv init -命令，这样每打开一个 bash 终端就可以调用 jenv 命令，并且默认执行一次 jenv init - 命令。"></a>三、执行 jenv init -命令，这样每打开一个 bash 终端就可以调用 jenv 命令，并且默认执行一次 jenv init - 命令。</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash"><span class="hljs-built_in">echo</span> <span class="hljs-string">&#x27;eval &quot;$(jenv init -)&quot;&#x27;</span> &gt;&gt; ~/.bash_profile</span><br><span class="hljs-meta prompt_">$ </span><span class="language-bash"><span class="hljs-built_in">source</span> ~/.bash_profile</span><br></code></pre></td></tr></table></figure>

<h5 id="四、查看当前的java版本，输出是1-8-0-44"><a href="#四、查看当前的java版本，输出是1-8-0-44" class="headerlink" title="四、查看当前的java版本，输出是1.8.0_44"></a>四、查看当前的java版本，输出是1.8.0_44</h5><figure class="highlight applescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs applescript">$ java -<span class="hljs-built_in">version</span><br></code></pre></td></tr></table></figure>

<h5 id="五、找到jdk1-8和jdk1-7的文件夹路径，加入到jenv的管理库："><a href="#五、找到jdk1-8和jdk1-7的文件夹路径，加入到jenv的管理库：" class="headerlink" title="五、找到jdk1.8和jdk1.7的文件夹路径，加入到jenv的管理库："></a>五、找到jdk1.8和jdk1.7的文件夹路径，加入到jenv的管理库：</h5><figure class="highlight dockerfile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs dockerfile">$ jenv <span class="hljs-keyword">add</span><span class="language-bash"> /opt/Java/jdk1.8.0_144</span><br>$ jenv <span class="hljs-keyword">add</span><span class="language-bash"> /opt/Java/jdk1.7.0_80</span><br></code></pre></td></tr></table></figure>

<h5 id="六、查看已经添加的java版本"><a href="#六、查看已经添加的java版本" class="headerlink" title="六、查看已经添加的java版本"></a>六、查看已经添加的java版本</h5><figure class="highlight crystal"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs crystal"><span class="hljs-variable">$ </span>jenv versions<br></code></pre></td></tr></table></figure>

<h5 id="七、配置要使用的JVM。有三种方式：global：按全局、lacal：按目录、shell：shell"><a href="#七、配置要使用的JVM。有三种方式：global：按全局、lacal：按目录、shell：shell" class="headerlink" title="七、配置要使用的JVM。有三种方式：global：按全局、lacal：按目录、shell：shell"></a>七、配置要使用的JVM。有三种方式：global：按全局、lacal：按目录、shell：shell</h5><figure class="highlight applescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs applescript">$ jenv <span class="hljs-keyword">global</span> jdk1<span class="hljs-number">.7</span><span class="hljs-number">.0</span>_80<br></code></pre></td></tr></table></figure>
<h5 id="或"><a href="#或" class="headerlink" title="或"></a>或</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">jenv <span class="hljs-built_in">local</span> jdk1.7.0_80</span><br></code></pre></td></tr></table></figure>
<h5 id="或-1"><a href="#或-1" class="headerlink" title="或"></a>或</h5><figure class="highlight mipsasm"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs mipsasm">$ <span class="hljs-keyword">jenv </span><span class="hljs-keyword">shell </span><span class="hljs-keyword">jdk1.7.0_80</span><br></code></pre></td></tr></table></figure>
<h5 id="八、查看当前java版本。发现版本已经变成了jdk1-7-0-80"><a href="#八、查看当前java版本。发现版本已经变成了jdk1-7-0-80" class="headerlink" title="八、查看当前java版本。发现版本已经变成了jdk1.7.0_80"></a>八、查看当前java版本。发现版本已经变成了jdk1.7.0_80</h5><figure class="highlight applescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs applescript">$ java -<span class="hljs-built_in">version</span><br></code></pre></td></tr></table></figure>
<h5 id="至此，以后再也不用自己手动修改环境变量改变java版本了。"><a href="#至此，以后再也不用自己手动修改环境变量改变java版本了。" class="headerlink" title="至此，以后再也不用自己手动修改环境变量改变java版本了。"></a>至此，以后再也不用自己手动修改环境变量改变java版本了。</h5>
                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/%E6%95%99%E7%A8%8B/">#教程</a>
      
        <a href="/tags/linux/">#linux</a>
      
        <a href="/tags/ubuntu/">#ubuntu</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>linux下java版本管理工具jenv使用介绍</div>
      <div>http://example.com/2019/05/02/java-env-ubuntu/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>wendao</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2019年5月2日</div>
        </div>
      
      
      <div class="license-meta-item">
        <div>许可协议</div>
        <div>
          
            
            
              <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
              <span class="hint--top hint--rounded" aria-label="BY - 署名">
                <i class="iconfont icon-by"></i>
              </span>
              </a>
            
          
        </div>
      </div>
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2019/05/02/java-sdaz/" title="手动安装java以及环境配置">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">手动安装java以及环境配置</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2019/04/19/test111111/" title="怀念一下我的博客">
                        <span class="hidden-mobile">怀念一下我的博客</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js" ></script>
<script  src="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://cdn.staticfile.org/typed.js/2.0.11/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://cdn.staticfile.org/tocbot/4.11.1/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      headingSelector : CONFIG.toc.headingSelector || 'h1,h2,h3,h4,h5,h6',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      collapseDepth   : CONFIG.toc.collapseDepth || 0,
      scrollSmooth    : true,
      headingsOffset  : -boardTop
    });
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }
  });
</script>


  <script src=https://cdn.staticfile.org/clipboard.js/2.0.6/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://cdn.staticfile.org/anchor-js/4.2.2/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));
  });
</script>


  
<script>
  Fluid.utils.createScript('https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
